package com.atcumt.meituan;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/* 
 * 股票推荐系统设计，每个用户可能关注几个公司，比如A,B,C，如果有另一个用户只关注了A，那么就会给他推荐B，C。
 * 这时候如果来了一个用户关注C，D，那么后来关注C的用户，都会推荐A，B(系统会记录连锁信息)，关注A的用户都会推荐BCD。
 * 在有上面的关系后，求用户查询的时候，会给它推荐的公司的个数。
 * 
 * 5
 * 1 Alice 2
 * Zoom Apple
 * 2 Bob
 * 2 Alice
 * 1 Bob 2
 * Apple Microsoft
 * 2 Bob
 */
public class Q2 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        UnionFind uf = new UnionFind(100000);
        Map<String, Integer> map1 = new HashMap<>(); // 每个名字在树的映射
        Map<String, Integer> map2 = new HashMap<>(); // 股票和 index 映射
        Map<String, Integer> map3 = new HashMap<>(); // 每个人对应的股票数映射
        int index = 0;
        for (int i = 0; i < N; i++) {
            int op = sc.nextInt();
            // 注册
            if (op == 1) {
                String name = sc.next();
                int n = sc.nextInt(); // 关注股票数
                map3.put(name, n);

                String stock = sc.next();
                int currIndex = -1;
                if (map2.containsKey(stock)) {
                    currIndex = map2.get(stock);
                } else {
                    currIndex = index++;
                }
                map1.put(name, currIndex);
                map2.put(stock, currIndex);

                // 遍历股票，并查集合并
                for (int j = 1; j < n; j++) {
                    int t = -1;
                    stock = sc.next();
                    if (map2.containsKey(stock)) {
                        t = map2.get(stock);
                    } else {
                        t = index++;
                    }
                    map2.put(stock, t);
                    uf.union(currIndex, t);
                    currIndex = t;
                }
            // 查询
            } else {
                String name = sc.next();
                if (!map3.containsKey(name)) {
                    System.out.println("error");
                    continue;
                }
                int root = uf.find(map1.get(name));
                int diff = uf.size[root] - map3.get(name);
                System.out.println(diff);
            }
        }
        sc.close();
    }
}

class UnionFind {
    int[] parent;
    int[] rank;
    int[] size;

    UnionFind(int n) {
        parent = new int[n];
        rank = new int[n];
        size = new int[n];
        for (int i = 0; i < n; i++) {
            parent[i] = i;
            size[i] = 1;
        }
    }

    int find(int x) {
        while (parent[x] != x) {
            x = parent[x];
        }
        return x;
    }

    void union(int x, int y) {
        int rootX = find(x);
        int rootY = find(y);
        if (rootX == rootY) {
            return;
        }
        parent[rootX] = rootY;
        size[rootY] += size[rootX];
    }
}
